// effect layer
var g_effectProxy=null;
var EffectProxy = cc.Node.extend({
    _heroEffect : null,
    _thingEffect : null,
    _enemyEffect : null,
    _heroBornEffect : null,
    _enemyBornEffect : null,
    ///////////////////////////
    ctor:function ( ) {
        this._super();
        g_effectProxy=this;
        this._heroEffect=new Array();
        this._thingEffect=new Array();
        this._enemyEffect=new Array();
        this._heroBornEffect=new Array();
        this._enemyBornEffect=new Array();
        return true;
    },
    onEnter:function () {
        this._super();
        for(var i=0;i<5;i++){
            this.newEnemyEffect();
        }
        for(var i=0;i<5;i++){
            this.newThingEffect();
        }
        for(var i=0;i<1;i++){
            this.newHeroEffect();
        }

        for(var i=0;i<1;i++){
            this.newHeroBornEffect();
        }
        for(var i=0;i<1;i++){
            this.newEnemyBornEffect();
        }
    },
    onExit : function() {
        this._heroEffect.splice(0,this._heroEffect.length);
        this._thingEffect.splice(0,this._thingEffect.length);
        this._enemyEffect.splice(0,this._enemyEffect.length);
        this._heroBornEffect.splice(0,this._heroBornEffect.length);
        this._enemyBornEffect.splice(0,this._enemyBornEffect.length);// */
        this._super();
    },
    ////////////////get effect///////////////////
    getHeroEffect : function() {
        var effects=this._heroEffect;
        for (var i=0;i<effects.length;++i){
            var effect = effects[i];
            if( !effect.getState() ){
                cc.log("get hero effect from buffer");
                return effect;
            }
        }
        return null;
    },
    getThingEffect : function() {
        var effects=this._thingEffect;
        for (var i=0;i<effects.length;++i){
            var effect = effects[i];
            if( !effect.getState() ){
                cc.log("get thing effect from buffer");
                return effect;
            }
        }
        return null;
    },
    getEnemyEffect : function() {
        var effects=this._enemyEffect;
        for (var i=0;i<effects.length;++i){
            var effect = effects[i];
            if( !effect.getState() ){
                cc.log("get enemy effect from buffer");
                return effect;
            }
        }
        return null;
    },
    getHeroBornEffect : function() {
        var effects=this._heroBornEffect;
        for (var i=0;i<effects.length;++i){
            var effect = effects[i];
            if( !effect.getState() ){
                cc.log("get hero born effect from buffer");
                return effect;
            }
        }
        return null;
    },
    getEnemyBornEffect : function() {
        var effects=this._enemyBornEffect;
        for (var i=0;i<effects.length;++i){
            var effect = effects[i];
            if( !effect.getState() ){
                cc.log("get enemy born effect from buffer");
                return effect;
            }
        }
        return null;
    },
    ////////////////new effect//////////////////
    newHeroEffect : function() {
        var effect=new Explosion("heroEs",null);
        effect.addMovementEventCallback();
        effect.setVisible(false);
        this.addChild(effect);
        this._heroEffect.push(effect);
        cc.log("new a hero effect");
        return effect;
    },
    newThingEffect : function() {
        var effect=new Explosion("ywtx",null);
        effect.addMovementEventCallback();
        effect.setVisible(false);
        this.addChild(effect);
        this._thingEffect.push(effect);
        cc.log("new a thing effect");
        return effect;
    },
    newEnemyEffect : function() {
        var effect=new Explosion("enemyEs",null);
        effect.addMovementEventCallback();
        effect.setVisible(false);
        this.addChild(effect);
        this._enemyEffect.push(effect);
        cc.log("new a enemy effect");
        return effect;
    },
    newHeroBornEffect : function() {
        var effect=new Explosion("xztx",null);
        effect.addMovementEventCallback();
        effect.setVisible(false);
        this.addChild(effect);
        this._heroBornEffect.push(effect);
        cc.log("new a hero born effect");
        return effect;
    },
    newEnemyBornEffect : function() {
        var effect=new Explosion("xztx",null);
        effect.addMovementEventCallback();
        effect.setVisible(false);
        this.addChild(effect);
        this._enemyBornEffect.push(effect);
        cc.log("new a enemy born effect");
        return effect;
    },
    ////////////////play effect///////////////////
    playHeroEffect:function(id,position){
        var effect=this.getHeroEffect();
        if(!effect){
            effect=this.newHeroEffect();
        }
        effect.setPosition(position);
        effect.playing(id);
    },
    playThingEffect:function(id,position){
        var effect=this.getThingEffect();
        if(!effect){
            effect=this.newThingEffect();
        }
        effect.setPosition(position);
        effect.playing(id);
    },
    playEnemyEffect:function(id,position){
        var effect=this.getEnemyEffect();
        if(!effect){
            effect=this.newEnemyEffect();
        }
        effect.setPosition(position);
        effect.playing(id);
    },
    playHeroBornEffect:function(id,position){
        var effect=this.getHeroBornEffect();
        if(!effect){
            effect=this.newHeroBornEffect();
        }
        effect.setPosition(position);
        effect.playing(id);
    },
    playEnemyBornEffect:function(id,position){
        var effect=this.getEnemyBornEffect();
        if(!effect){
            effect=this.newEnemyBornEffect();
        }
        effect.setPosition(position);
        effect.playing(id);
    }
});
////////////////////get effect instance////////////////////
GetEffectProxy=function(){
    if(g_effectProxy){
        return g_effectProxy;
    }else{
        cc.log("invalid g_effectProxy");
        return null;
    }
}
///////////////////////play effect/////////////////////////
PlayHeroEffect=function(id,position){
    var effectProxy=GetEffectProxy();
    effectProxy.playHeroEffect(id,position);
}
PlayThingEffect=function(id,position){
    var effectProxy=GetEffectProxy();
    effectProxy.playThingEffect(id,position);
}
PlayEnemyEffect=function(id,position){
    var effectProxy=GetEffectProxy();
    effectProxy.playEnemyEffect(id,position);
}